package com.ww.learn.coroutine.context

import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

// 打印结果
//request: I'm done
//Coroutine 0 is done
//Coroutine 1 is done
//Coroutine 2 is done
//Now processing of the request is complete

// 启动一个协程来处理某种传入请求
fun main() = runBlocking {
    val request = launch {
        repeat(3) { i -> // 启动少量子作业
            launch {
                delay((i + 1) * 200L)
                println("Coroutine $i is done")
            }
        }
        println("request: I'm done")
    }
    request.join() // 等待请求的完成，包括其所有子协程
    println("Now processing of the request is complete")
}